package com.vercon.commonmirror;

import android.content.Context;

import com.vercon.commonmirror.component.IToastComponent;


/**
 * Created by sure on 2017/11/11.
 */

public class ToastManager {

    public static boolean LOG_DEBUG = BuildConfig.DEBUG;
    private static final ToastManager ourInstance = new ToastManager();

    private Context context;
    private IToastComponent toastComponent;

    public static ToastManager instance() {
        return ourInstance;
    }

    private ToastManager() {
    }
    public void initialize(Context ctx) {
        if (null != ctx) {
            context = ctx.getApplicationContext();
        }
    }

    public void error(String message) {
        toastComponent.error(message);
    }

    public void error(String message, int length) {
        toastComponent.error(message, length);
    }

    public void success(String message) {
        toastComponent.success(message);
    }

    public void success(String message, int length) {
        toastComponent.success(message, length);
    }

    public void debug(String message) {
        if(LOG_DEBUG) {
            toastComponent.debug(message);
        }
    }

    public void setToastComponent(IToastComponent toastComponent) {
        this.toastComponent = toastComponent;
    }

//    public class DefaultToastComponent implements IToastComponent{
//
//        @Override
//        public void error(String message) {
//            toast(message, context, Toast.LENGTH_SHORT).show();
//        }
//
//        @Override
//        public void success(String message) {
//            toast(message, context, Toast.LENGTH_SHORT).show();
//        }
//
//        public Toast toast(String message, Context context, int length) {
//            return Toast.makeText(context, message, length);
//        }
//    }


}
